package Exercise4.exercise4;
import java.math.BigDecimal;
import java.util.*;
public class Test1 {
	public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个数：");
        String inputString = in.nextLine();
        BigDecimal bigDecimal = new BigDecimal(inputString);//BigDecimal可以精确计算
        String string = bigDecimal.toString();
        char[] charArray = string.toCharArray();
        StringBuffer buffer = new StringBuffer();//与String相似，但是StringBuffer对象能多次被修改
        // 从个位数
        int sum=0;
        for (int i = charArray.length - 1; i >= 0; i--)
        {
            System.out.println("第" + (charArray.length - i) + "位：" + charArray[i]);
            buffer.append(charArray[i] + " ");//append在对象后面追加字符串
            sum+=charArray[i]-'0';
        }
        System.out.println(sum);
    }
}